package com.aaa.controller;

import com.aaa.entity.Discuss;
import com.aaa.service.DiscussService;
import com.aaa.util.DefaultMsg;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 评论管理控制器
 */
@RestController
@RequestMapping("/discuss")
public class DiscussController {
    @Resource
    private DiscussService discussService;

    /**
     * 查询所有评论
     * @param keyword
     * @param currentPage
     * @param pageSize
     * @return
     */
    @PostMapping("/listData")
    public PageInfo<Discuss> listData(@RequestParam(defaultValue = "") String keyword, Integer currentPage, Integer pageSize){
        PageHelper.startPage(currentPage,pageSize);
        List<Discuss> discussList = discussService.listAll(keyword);
        PageInfo pageInfo=new PageInfo(discussList);
        return pageInfo;
    }

    /**
     * 根据did删除评论
     * @param did
     * @return
     */
    @RequestMapping("del")
    public DefaultMsg delete(Integer did){
        DefaultMsg defaultMsg = discussService.delete(did);
        return defaultMsg;
    }
}
